<?php
class IndexAction extends Action
{

    public  function  vbs()
    {
        $temp=$this->InitClassSelectOption("tasktype",0,2);
         $this->str=$temp;
        $this->display();

    }

    private function  InitClassSelectOption($tables,$ParentID,$ChkID)
    {

        $str = "";
        $model = M($tables);
        $condition["parentid"] = $ParentID;
        $data = $model->where($condition)->select();
        $template = '<option value="%d" %s >%s</option>';

        foreach ($data as $k => $v)
        {
            $checked = '';
            $prefix = '';
            $sortpath = trim($v["path"]);
            if (substr($sortpath, -1) == ',')
            {
                $sortpath = substr($sortpath, 0, -1);
            }

            $path_arr = explode(",", $sortpath);
            $pathlen = count($path_arr);
            for ($i = 0; $i < $pathlen - 2; $i++) //---------------是因为后边有一个多余的,前面公有的是0
            {
                $prefix .= "│&nbsp;";
            }
            if ($ChkID == $v['id'])
            {
                $checked = 'selected="selected"';
            }
            $str .= sprintf($template, $v['id'], $checked, $prefix . '├' . $v["name"]);
            $str .= $this->InitClassSelectOption($tables, $v['id'], $ChkID);

        }

        return $str;
    }

    public function test()
    {
        $topid = 0;
        $Form = M('project');
        $list = $Form->order(" id asc")->select();
        $this->depart_list = $list;
        $this->display();
    }
    public function index()
    {
        header("location:system.php");
        //$this->redirect("/system.php");
        //$this->display();
    }


    public function  tst()
    {
        $this->display();
    }

    public  function  getNode()
    {
        $type=I("get.type");
        switch($type)
        {
            case "pro":
                break;
            case "site":
                break;
            case "task":
                break;
        }

        $cdata = '[{"label":"Saurischia","id":"1",
        "children":[{
            "label": "apple", "id":"2","children":[{
                "label": "orange", "id":"3"
                }]
        }]
        },
 {"label":"Ornithischians","id":"23"}]';
        echo $cdata;
    }

    public function AjaxHead()
    {
        @header("Pragma:no-cache\r\n");
        @header("Cache-Control:no-cache\r\n");
        @header("Expires:0\r\n");
    }

    function PutCookie($key, $value, $kptime = 0, $pa = "/")
    {
        global $cfg_cookie_encode, $cfg_domain_cookie;
        setcookie($key, $value, time() + $kptime, $pa, $cfg_domain_cookie);
        setcookie($key . '__ckMd5', substr(md5($cfg_cookie_encode . $value), 0, 16), time() + $kptime, $pa, $cfg_domain_cookie);
    }

    public function  catalog_edit()
    {
        $this->display("catalog_add");
    }

    public function  catalog_add()
    {
        $this->display();
    }


    public function catalog_do()
    {

        $dopost = I("get.dopost", '');
        $cid = I('get.cid', 0);
        if (empty($dopost))
        {
            $this->error("对不起，请指定栏目参数");
        }

        if ($dopost == "GetSunLists")
        {
            import('Common.Typeunit', APP_PATH, '.class.php');
            $this->AjaxHead();
            $this->PutCookie('lastCidMenu', $cid, 3600 * 24, "/");
            $tu = new TypeUnit();
            echo "    <table width='100%' border='0' cellspacing='0' cellpadding='0'>\r\n";
            $tu->LogicListAllSunType($cid, "　");
            echo "    </table>\r\n";
        }
    }

    /**
     *  读出所有分类,在类目管理页(list_type)中使用
     *
     * @access    public
     * @param     int $table  表名
     * @param     int $topid  当前操作ID
     * @return    string
     */
    public function ListType($table = "department", $topid = 0)
    {
        $Form = M($table);
        $list = $Form->where('parentid=' . $topid)->order(" id asc")->select();
        /*     echo $Form->getLastSql();
         dump($list);
         exit() ;
          $this->depart_list=$list;*/

        foreach ($list as $k => $v) {
            echo '<tr align="center"  bgcolor="#FBFCE2" height="22" class="fid"><td width="7%"><span class="jia"></span>ID</td><td width="14%">' . $v['id'] . '</td><td width="14%">' . $v['name'] . '</td><td>操作</td></tr>';
            $this->ListTypeSeed($table, $v['id']);
        }
    }

    /**
     *  读出子分类
     *
     * @access    public
     * @param     int $table  表名
     * @param     int $topid  当前操作ID
     * @return    string
     */
    private function ListTypeSeed($table, $topid)
    {
        $Form = M($table);
        $list = $Form->where('topid=' . $topid)->order("sort desc,id asc")->select();
        if ($list) {
            echo '<tr align="center"  bgcolor="#FFFFFF" height="22" class="seed"><td colspan="4"><table width="98%">';
            foreach ($list as $k => $v) {
                echo '<tr align="center" bgcolor="#FAFAF1" height="22"><td width="7%"><span class="jia"></span>ID</td><td width="14%">' . $v['id'] . '</td><td width="14%">' . $v['name'] . '</td><td>操作</td></tr>';
                $this->ListTypeSeed("keshi", $v['id']);
            }
            echo '</table></td></tr>';
        }
    }
}


?>